import {Component, Input, OnInit} from '@angular/core';
import {AlertComponent} from "../../unit/alert";

@Component({
  selector: 'app-send-verification-code',
  templateUrl: './send-verification-code.component.html',
  styleUrls: ['./send-verification-code.component.scss'],
})
export class SendVerificationCodeComponent implements OnInit {
  @Input() phoneNumber:string;

  countNumber: number;
  timer: NodeJS.Timeout | null;
  constructor(
      public alertComponent: AlertComponent
  ) { }

  ngOnInit() {}

  getValidateCode(){
    if(!this.phoneNumber){
      this.alertComponent.presentAlert('请填写手机号码').then(r => {});
      return;
    }
    // send code
    this.countNumber = 60;
    this.timer = setInterval(this.setTimer.bind(this),1000);
  }
  setTimer(){
    if (this.countNumber < 1) {
      clearInterval(this.timer);
      this.timer = null;
      return;
    }
    this.countNumber -= 1;
  }

}
